<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.staticfile.org/vue/3.0.5/vue.global.js"></script>
</head>

<body>
    <div id="app" class="demo">

        <div v-if="tab_status">
            <one></one>
        </div>
        <div v-else="tab_status">
            <async-two></async-two>
        </div>

        <button @click="my_click">更换组件，请看控制台网络</button>
    </div>

    <template id="one">
        <div style="color: rebeccapurple;">你好啊，兄弟额</div>
    </template>

    <template id="two">
        <h1>哈哈哈哈哈</h1>
    </template>
</body>
<script>
    const HelloVueApp = {
        data() {
            return {
                tab_status: true
            }
        },
        methods: {
            my_click() {
                this.tab_status = !this.tab_status;
            }
        },
        components: {
            one: { template: '#one' }
        }
    }
    const app = Vue.createApp(HelloVueApp);
    //在单页面开发看不出效果。
    const AsyncComp = Vue.defineAsyncComponent(
        () =>
            new Promise((resolve, reject) => {
                resolve({
                    template: '#two'
                })
            })
    )
    app.component('async-two', AsyncComp);
    const vue = app.mount('#app')

</script>

</html>